package main
 
import (
  "log"
  "os/exec"
  "strconv"
  "strings"
)

func NumberStringFormat(src string) string {
  // 去除空格  
  str := strings.Replace(src, " ", "", -1)  
  // 去除换行符  
  str = strings.Replace(str, "\n", "", -1)
  log.Printf("%s", str)
  return str  
}

func ShellCmdExecutor(cmd string, retval_type string) float64 {
  var retval float64
  var c *exec.Cmd
  if GlobalConfig.Exporter.Osenv == "linux" {
    // linxu bash shell
  	c = exec.Command("bash", "-c", cmd)
  } else if GlobalConfig.Exporter.Osenv == "win64_pwsh" {
    // windows powershell版本
    c = exec.Command("powershell", "-Command", cmd)
  } else if GlobalConfig.Exporter.Osenv == "win64_cmd" {
	  // windows cmd版本
  	c = exec.Command("cmd", "/C", cmd)
  }

  output, err := c.CombinedOutput()
  //log.Println(string(output))

  if err != nil {
  	retval = 0.0
  } else {
  	f64,err := strconv.ParseFloat(NumberStringFormat(string(output)), 64)
  	if err != nil {
  		retval = 0.0
  	} else {
  		retval = f64
  	}
  }
  //log.Println(retval)
  return retval
}